//package com.dongwu.security.web;
//
//import java.util.List;
//
//import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.CellType;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.Sheet;
//import org.apache.poi.ss.usermodel.Workbook;
//import org.apache.poi.ss.usermodel.WorkbookFactory;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.ModelMap;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.google.common.collect.Lists;
//import com.dongwu.common.web.RoleBaseController;
//import com.dongwu.security.model.UserImportData;
//import com.dongwu.security.service.IGroupService;
//import com.dongwu.security.service.IUserService;
//import com.dongwu.security.utils.SecurityUtils;
//
//@Controller
//@RequestMapping("/security/user")
//public class UserImportController extends RoleBaseController {
//
//	protected Logger logger = LoggerFactory.getLogger(this.getClass());
//	
//	@Autowired
//	private IGroupService groupService;
//
//	@Value("${dongwu.security.user.addRole}")
//	private String addRole;
//
//	@Autowired
//	private IUserService userService;
//	
//	@RequestMapping(value = "/user-import")
//	public String userImport(ModelMap model) {
//		if (!SecurityUtils.hasRole(addRole)) {
//			return DENY_PAGE;
//		}
//		return "security/user/user-import";
//
//	}
//	
//	@RequestMapping(value = "/do-user-import",produces = "text/html;charset=UTF-8")
//	@ResponseBody
//	public String doThirdpartyPaymentImport(@RequestParam("file") MultipartFile file) {
//		if (file.isEmpty()) {
//			return "上传失败，文件内容为空";
//		}
//		if (!SecurityUtils.hasRole(addRole)) {
//			return DENY_MESSAGE;
//		}
//		try {
//			Workbook workbook = WorkbookFactory.create(file.getInputStream());
//			Sheet sheet = workbook.getSheetAt(0);
//			List<UserImportData> userImportDatas = Lists.newArrayList();
//			for (int i = 1; i <= sheet.getLastRowNum(); i++) {
//				Row row = sheet.getRow(i);
//				String jobNo = readCellStringForce(row.getCell(0));// 员工工号
//				String name = row.getCell(1).getStringCellValue(); // 员工姓名
//				String postName = row.getCell(2).getStringCellValue(); // 岗位
//				String roleGroupId = readCellStringForce(row.getCell(3)); // 所需角色
//				String roleGroupName = row.getCell(4).getStringCellValue(); // 角色描述
//				String dataPermission = readCellStringForce(row.getCell(5)); // 所需数据权限
//				if (logger.isDebugEnabled()) {
//					logger.debug("员工工号	:{} 员工姓名	:{} 岗位	:{} 所需角色:{} 角色描述:{} 所需数据权限:{} ", jobNo, name, postName,
//							roleGroupId, roleGroupName, dataPermission);
//				}
//				
//				UserImportData userImportData = new UserImportData(jobNo, name, postName,
//						roleGroupId, roleGroupName, dataPermission);
//				userImportDatas.add(userImportData);
//			}
//			userService.importUser(userImportDatas);
//			return "上传成功";
//		} catch (Exception e) {
//			logger.error(e.getMessage(), e);
//			return "上传失败" + e.getMessage();
//		}
//
//	}
//
//	protected String readCellStringForce(Cell cell) {
//		cell.setCellType(CellType.STRING);
//		cell.getStringCellValue(); 
//		String jobNo = cell.getStringCellValue();
//		return jobNo;
//	}
//}
